<?php

namespace App\Models\Elasticsearch\Order;

use App\Models\Elasticsearch\Model;

class Wallet extends Model
{

    const INDEX_NAME = 't_third_wallet_order';

    /**
     * 状态【创建订单】
     *
     * @var integer
     */
    const STATUS_INIT = 1;

    /**
     * 状态【订单完成】
     *
     * @var integer
     */
    const STATUS_SUCCEED = 2;

    /**
     * 状态【订单已撤销】
     *
     * @var integer
     */
    const STATUS_REVOCATION = 3;

    /**
     * 获取订单数据
     *
     * @param string $sn
     * @param string|null $platCode
     * @return array|null
     */
    protected function getData(string $sn, ?string $platCode = null): ?array
    {
        $params = ['body' => ['size' => 1, 'track_total_hits' => false]];
        // 数据筛选
        $params['body']['query']['bool']['must'][] = [
            'term' => ['sn' => $sn]
        ];
        // 平台筛选
        if (!is_null($platCode)) {
            $params['body']['query']['bool']['must'][] = [
                'term' => ['plat_code' => $platCode]
            ];
        }
        // 查询数据
        $results = $this->search($params);

        return $results['hits']['hits'][0]['_source'] ?? null;
    }
}
